//
//  MakePhoneView.m
//  GoldOperationClient
//
//  Created by yaxue wang on 2016/11/21.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "MakePhoneView.h"

@interface MakePhoneView ()
@property (nonatomic, strong)NSMutableArray *typeAr;
@property (nonatomic, strong) void(^action)(NSInteger index);
@property (nonatomic, strong) UIView *boxView;

@end
@implementation MakePhoneView





- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
       
    }
    return self;
}

+(MakePhoneView *) showTitle:(NSString *)title context:(NSString *)context action:(void(^)(NSInteger index))action{
    MakePhoneView *boxView = [[MakePhoneView alloc] init];
    boxView.action = action;
    boxView.title=title;
    boxView.context=context;
    [boxView showBox];
    return boxView;
}

- (void) initView{
    
    
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    [self addSubview:bgView];
    [bgView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.6]];
    [bgView bk_whenTapped:^{
        [self hideBox];
    }];
    float width = self.frame.size.width * 2 / 3;
    float height = 140;
    _boxView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [_boxView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:_boxView];
    [_boxView setCenter:self.center];
    [_boxView.layer setCornerRadius:5];
    
    UILabel *nameLab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, width, 30)];
    nameLab.textColor=MainColor;
    nameLab.textAlignment=NSTextAlignmentCenter;
    nameLab.font=F(12);
    nameLab.text=self.title;
    [_boxView addSubview:nameLab];
    UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(10, 30, width-20, 0.5)];
    line.backgroundColor=LineColor;
    [_boxView addSubview:line];
    UILabel *contextLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 30.5, width-20, height-30-15-30.5)];
    contextLab.numberOfLines=0;
    contextLab.text=self.context;
    contextLab.textColor=C(@"878888");
    contextLab.font=F(15);
    contextLab.textAlignment=NSTextAlignmentCenter;
    [_boxView addSubview:contextLab];
    UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(15, height-15-25, width - 30, 25)];
    btnView.layer.masksToBounds=YES;
    btnView.layer.cornerRadius=5;
    [_boxView addSubview:btnView];
    UILabel *btnLab=[[UILabel alloc]initWithFrame:CGRectMake(20, height-25-15, width-40, 30)];
    btnLab.textColor=MainColor;
    btnLab.textAlignment=NSTextAlignmentCenter;
    [_boxView addSubview:btnLab];
    btnLab.text=@"确定";
    btnLab.font=F(14);
    btnLab.layer.masksToBounds=YES;
    btnLab.layer.cornerRadius=3;
    btnLab.layer.borderColor=MainColor.CGColor;
    btnLab.layer.borderWidth=0.5;
    btnLab.userInteractionEnabled=YES;
    [btnLab bk_whenTapped:^{
        if (self.action) {
            [self hideBox];
            self.action(1);
        }
    }];

    
}
- (void) showBox{
    [self initView];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];

   }

- (void) hideBox{
    [self removeFromSuperview];
}




@end
